<%@page import="systems.Recently"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="systems.RecentlyTag"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.ArticleSearch"%>
<%@page import="entities.Article"%>
<%@page import="models.CategoryModel"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
CategoryModel categoryModel = CategoryModel.getInstance();
List<Category> categories = categoryModel.getAll();
List<Article> articles = Recently.getArticles("", "lastest_article");
List<String> tags = RecentlyTag.getTags();
String hasArchives = (String) request.getParameter("hasArchives");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

		<div class="span4 sidebar">
				<div class="block searchbar">
					<h3>Search</h3>
					<div class="block-content">
						<form class="form-search" action="/search" id="searchform" method="get">
							<input type="text" class="input-medium" id="s" name="q" value="" placeholder="Enter Content">
							<input type="submit" class="btn btn-success" value="Search" id="searchsubmit">
						</form>
					</div>
				</div>
				
				<% if (hasArchives != null) { %>
            	<%
            	Calendar cal = Calendar.getInstance();
            	int currentYear = cal.get(Calendar.YEAR);
            	int year = currentYear;
            	int month = cal.get(Calendar.MONTH)+1;
            	int countMonth = DateHelper.getCountMonthFromNow(1, 2013);
            	int count = 1;
            	%>
				<div class="block archives">
					<h3>Archives</h3>
					<div class="block-content">
						<div class="row-fluid">
							<div class="span6">
								<h3><%=year %></h3>
								<ul>
								<%
			                    	for (int i = 0; i < countMonth + 1; i++) {
			                    		//if (currentYear - year > 1) break;
			                    	%>
									<li><a href="/archives/<%=month <10 ? "0" + month : month %>-<%=year%>"><%=DateHelper.getMonthName(month-1) %>&nbsp;<%=year %></a></li>
									<%
		                        	month -= 1;
		                			if (month <= 0) {
		                				count++;
		                				month = 12;
		                				year -= 1;
		                				if (i < countMonth) {
		                			%>
								</ul>
							</div>
							<% if (count %2 == 1 ) { %>
							</div>
							<div class="row-fluid">
							<% } %>
							<div class="span6">
								<h3><%=year %></h3>
								<ul>
									<%
                				}
                			}
                        } %>  
								</ul>
							</div>
						</div>
					</div>
				</div>
				<% } %>
				
				<div class="block">
					<h3>Recent Posts</h3>
					<div class="block-content">
						<ul>
							<% 
							for (int i = 0; i < articles.size(); i++) { 
								if (i > 10) break;
							%>
							<li  itemscope itemtype="http://schema.org/Article" itemprop="itemListElement">
								<a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a>
							</li>
							<% } %>
						</ul>
					</div>
				</div>
				
				<div class="block">
					<h3>Categories</h3>
					<div class="block-content">
						<ul>
							<% for (int i = 0 ; i < categories.size(); i++ ) { %>
							<li><a href="/category/<%=categories.get(i).getAlias() %>" title="Category <%=categories.get(i).getName() %>" ><%=categories.get(i).getName() %></a></li>
							<% } %>
						</ul>
					</div>
				</div>
				
				<div class="block">
					<h3>Tags</h3>
					<div class="block-content">
						<div class="tagcloud">
							<%
	                    	for (int i = 0; i < tags.size(); i++) {
	                    		if (i > 50) break;
	                    	%>
							<a class="tag" style="font-size: 8pt" href="/tag/<%=URLEncoder.encode(tags.get(i))%>"><%=tags.get(i) %></a>,
							<% } %>
						</div>
					</div>
				</div>

			</div>